package service.Impl;

import dao.Impl.TclassifyDaoImpl;
import dao.Impl.TgoodsDaoImpl;
import dao.TclassifyDao;
import dao.TgoodsDao;
import pojo.Tclassify;
import pojo.Tgoods;
import service.Tclassifyservice;

import java.util.List;

public class TclassifyserviceImpl implements Tclassifyservice {

    TclassifyDao tc = new TclassifyDaoImpl();
    TgoodsDao tg = new TgoodsDaoImpl();

    @Override
    public Tclassify selall() {
        Tclassify tclassify = new Tclassify();

        //获取所有一级菜单
        List<Tclassify> seltclassify = tc.seltclassify(0);
        //循环获取二级菜单及一级菜单下的商品信息
        for (Tclassify tclassify1 : seltclassify) {
            List<Tclassify> seltclassify1 = tc.seltclassify(tclassify1.getId());
            tclassify1.setTclassifys(seltclassify1);
            //循环二级菜单获取三级菜单
            for (Tclassify tclassify2 : seltclassify1) {
                List<Tclassify> seltclassify3 = tc.seltclassify(tclassify2.getId());
                tclassify2.setTclassifys(seltclassify3);
            }
            //一级菜单下商品
            List<Tgoods> all = tg.all(tclassify1.getId(), "", 1, 6);
            tclassify1.setTgoods(all);
        }
        tclassify.setTclassifys(seltclassify);

        return tclassify;
    }

    @Override
    public List<Tclassify> sel(int id) {
        return tc.seltclassify(id);
    }
}
